library(ggplot2)
library(ggprism)
library(dplyr)
library(ggsignif)
library(ggthemr) # 载入主题配置包

setwd("C:\\Users\\dell\\Desktop\\")

data <- read.csv("telomere_cmp_PePsPyu.csv", header = T)
data$Specie <- factor(data$Specie,levels=c('Pythium_oligandrum', 'Peronospora_effusa',
                                           'PsojaeJS2'),
                    ordered = TRUE)#按照上图的顺序排列
unique(data$Specie)
compaired <- list(c('Pythium_oligandrum', 
                    'PsojaeJS2'))

P1 <- ggplot(data=data, mapping = aes(x=Specie, y=Len, fill=Specie)) +
  stat_boxplot(geom='errorbar', width =0.15, color="black") +
  #"trim"如果为TRUE(默认值), 则将小提琴的尾部修剪到数据范围。如果为FALSE, 不修剪尾部。
  geom_boxplot(width=0.5, position=position_dodge(0.9), outlier.color="white") + #绘制箱线图, position=position_dodge(0.9),
  scale_fill_manual(values = c("#D3D3D3","#808B96", "#808B96")) + 
  
  geom_jitter(color="darkblue", shape=1, size=2, width=0.1) +
#  theme_prism() +
  ylab("") +
  xlab("")

P1 + 
  stat_signif(comparisons = compaired,
              step_increase = 0.1,
              map_signif_level = F,
              test = "wilcox.test",
              test.args = list(alternative = "two.sided", 
                               var.equal = FALSE, paired=FALSE))

# the test.args have to be a list, not a vector.
# https://github.com/const-ae/ggsignif/issues/7
